package bcontractor.base;

import java.util.Iterator;

import bcontractor.api.Sentence;
import bcontractor.api.SentenceSet;

/**
 * Utility class for set manipulation operations.
 * 
 * @author lundberg
 * 
 */
public final class SetUtils {

    public static <S extends Sentence<S>> SentenceSet<S> intersection(Iterable<SentenceSet<S>> sets) {
        Iterator<SentenceSet<S>> it = sets.iterator();
        if (!it.hasNext()) {
            return emptySentenceSet();
        }
        SentenceSet<S> result = it.next();
        while (it.hasNext()) {
            result = result.intersection(it.next());
        }
        return result;
    }

    public static <S extends Sentence<S>> SentenceSet<S> emptySentenceSet() {
        return new PureSentenceSet<S>();
    }
}
